<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    if (!function_exists('price_list_table')) {

        function price_list_table($CI, &$data) {

            $CI->load->library('table');
            $periods = $data['details']->priceList->periods;
            $prices = $data['details']->priceList->prices;

            $CI->load->library('factory');
            $CI->factory->create('translate');

            $headings = array(lang('minpersons'), lang('mindays'));

            foreach ($periods as $row)
                $headings[] = date('d.m', $row->start) . ' <span>-</span> ' . date('d.m', $row->end);

            $CI->table->set_heading($headings);

            foreach ($prices as $row) {

                $prcs = array($row->selling_min_person, $row->selling_min_ng);

                foreach ($periods as $rowPeriod):
                    $price = $CI->strparse->find_lang_in_string(trim($row->selling_periods), $rowPeriod->ID);
                    $prcs[] = $price == 0 ? "" : $price;
                endforeach;

                $CI->table->add_row($prcs);
            }

//            $this->firephp->log($data['details']);

            $data['priceListHTML'] = $CI->table->generate();
        }

    }
